﻿<UserControl x:Class="ProductManager.WPF.Presentation.Views.ProductView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:p="clr-namespace:ProductManager.WPF.Presentation.Properties"
             xmlns:vm="clr-namespace:ProductManager.WPF.Applications.ViewModels;assembly=ProductManager.WPF.Applications"
             xmlns:util="clr-namespace:ProductManager.WPF.Presentation.Util"
             mc:Ignorable="d" d:DataContext="{d:DesignData Source=../DesignData/SampleProductViewModel.xaml}"
             xmlns:c="clr-namespace:ProductManager.WPF.Presentation.Converters"
             IsEnabled="{Binding IsEnabled}">
    
    <UserControl.Resources>
        <c:PositiveDecimalConverter x:Key="PositiveDecimalConverter" />
    </UserControl.Resources>

    <Grid Margin="5">
        <!--<Grid.DataContext>
            <PriorityBinding>
                <Binding Path="Product" />
            </PriorityBinding>
        </Grid.DataContext>-->
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="120" />
            <ColumnDefinition Width="20" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="120" />
            <ColumnDefinition Width="20" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="35" />
            <RowDefinition Height="35" />
            <RowDefinition Height="35" />
            <RowDefinition Height="35" />
            <RowDefinition Height="35" />
            <RowDefinition Height="35" />
            <RowDefinition Height="35" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <!-- row 0 -->
        <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="0">
            <Label Content="{x:Static p:Resources.ID}"  VerticalAlignment="Center" FontWeight="Bold" />
            <Label Content="{Binding Product.ProductID}" VerticalAlignment="Center" FontWeight="Bold" />            
        </StackPanel>

        <Label Content="{x:Static p:Resources.ModifiedDate}" Grid.Column="3" Grid.Row="0" VerticalAlignment="Center" />
        <TextBox Text="{Binding Product.ModifiedDate, StringFormat='dd.MM.yyyy HH:mm:ss'}" Grid.Column="4" Grid.Row="0" 
                 VerticalAlignment="Center" Background="Transparent" BorderBrush="Transparent" IsReadOnly="True" />

        <!-- row 1 -->
        <Label Content="{x:Static p:Resources.Name}" Grid.Column="0" Grid.Row="1" VerticalAlignment="Center" />
        <TextBox Name="NameField" Text="{Binding Product.Name, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, ValidatesOnDataErrors=True}" 
                 MaxLength="100" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" />
        <ContentControl Grid.Column="2" Grid.Row="1" Style="{DynamicResource ChangeMarker}" 
                        util:ChangeMarker.Entity="{Binding Product}" util:ChangeMarker.PropertyName="Name" />

        <Label Content="{x:Static p:Resources.Size}" Grid.Column="3" Grid.Row="1" VerticalAlignment="Center" />
        <TextBox x:Name="SizeTextBox" Grid.Column="4" Grid.Row="1" Text="{Binding Product.Size, UpdateSourceTrigger=PropertyChanged, 
                 ValidatesOnExceptions=True, ValidatesOnDataErrors=True, TargetNullValue={x:Static sys:String.Empty}}"
                 HorizontalAlignment="Stretch" VerticalAlignment="Center" />
        <ContentControl Grid.Column="5" Grid.Row="1" Style="{DynamicResource ChangeMarker}" 
                        util:ChangeMarker.Entity="{Binding Product}" util:ChangeMarker.PropertyName="Size" />
       
        <!-- row 2 -->
        <Label Content="{x:Static p:Resources.ProductNumber}" Grid.Column="0" Grid.Row="2" VerticalAlignment="Center" />
        <TextBox Text="{Binding Product.ProductNumber, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, ValidatesOnDataErrors=True}" 
                 MaxLength="100" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
        <ContentControl Grid.Column="2" Grid.Row="2" Style="{DynamicResource ChangeMarker}" 
                        util:ChangeMarker.Entity="{Binding Product}" util:ChangeMarker.PropertyName="ProductNumber" />

        <Label Content="{x:Static p:Resources.Weight}" Grid.Column="3" Grid.Row="2" VerticalAlignment="Center" />
        <TextBox x:Name="WeightTextBox" Grid.Column="4" Grid.Row="2" Text="{Binding Product.Weight, UpdateSourceTrigger=PropertyChanged, 
                 ValidatesOnExceptions=True, ValidatesOnDataErrors=True, TargetNullValue={x:Static sys:String.Empty}}"
                 HorizontalAlignment="Stretch" VerticalAlignment="Center" />
        <ContentControl Grid.Column="5" Grid.Row="2" Style="{DynamicResource ChangeMarker}" 
                        util:ChangeMarker.Entity="{Binding Product}" util:ChangeMarker.PropertyName="Weight" />

        <!-- row 3 -->
        <Label Content="{x:Static p:Resources.ListPrice}" Grid.Column="0" Grid.Row="3" VerticalAlignment="Center" />
        <TextBox Text="{Binding Product.ListPrice, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, 
                 Converter={StaticResource PositiveDecimalConverter}}" IsEnabled="{Binding IsCurrencyEnabled}"
                 MaxLength="100" Grid.Column="1" Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Center" />
        <ContentControl Grid.Column="2" Grid.Row="3" Style="{DynamicResource ChangeMarker}" 
                        util:ChangeMarker.Entity="{Binding Product}" util:ChangeMarker.PropertyName="ListPrice" />

        <Label Content="{x:Static p:Resources.SellStartDate}" Grid.Column="3" Grid.Row="3" VerticalAlignment="Center" />
        <!--<DatePicker Grid.Column="4" Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Center"
                    SelectedDate="{Binding SellStartDate}" />-->
        <TextBox Text="{Binding Product.SellStartDate, StringFormat=d, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, 
                 TargetNullValue={x:Static sys:String.Empty}}"
                 MaxLength="100" Grid.Column="4" Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Center" />
        <ContentControl Grid.Column="5" Grid.Row="3" Style="{DynamicResource ChangeMarker}" 
                        util:ChangeMarker.Entity="{Binding Product}" util:ChangeMarker.PropertyName="SellStartDate" />

        <!-- row 4 -->
        <Label Content="{x:Static p:Resources.Color}" Grid.Column="0" Grid.Row="4" VerticalAlignment="Center" />
        <TextBox Text="{Binding Product.Color, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, 
                 TargetNullValue={x:Static sys:String.Empty}}"
                 MaxLength="100" Grid.Column="1" Grid.Row="4" HorizontalAlignment="Stretch" VerticalAlignment="Center" />
        <!--<ComboBox ItemsSource="{Binding Source={StaticResource ProductColorFilterValues}}"
                  SelectedItem="{Binding Color}" Grid.Column="1" Grid.Row="4"
                  HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="0"
                  AllowDrop="True">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Converter={x:Static c:ProductColorToStringConverter.Default}}"/>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>-->
        <ContentControl Grid.Column="2" Grid.Row="4" Style="{DynamicResource ChangeMarker}" 
                        util:ChangeMarker.Entity="{Binding Product}" util:ChangeMarker.PropertyName="Color" />

        <Label Content="{x:Static p:Resources.SellEndDate}" Grid.Column="3" Grid.Row="4" VerticalAlignment="Center" />
        <!--<DatePicker Grid.Column="4" Grid.Row="4" HorizontalAlignment="Stretch" VerticalAlignment="Center"
                    SelectedDate="{Binding SellEndDate}" />-->
        <TextBox Text="{Binding Product.SellEndDate, StringFormat=d, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, 
                 TargetNullValue={x:Static sys:String.Empty}}"
                 MaxLength="100" Grid.Column="4" Grid.Row="4" HorizontalAlignment="Stretch" VerticalAlignment="Center" />
        <ContentControl Grid.Column="5" Grid.Row="4" Style="{DynamicResource ChangeMarker}" 
                        util:ChangeMarker.Entity="{Binding Product}" util:ChangeMarker.PropertyName="SellEndDate" />

        <!-- row 5 -->
        <Label Content="{x:Static p:Resources.StandardCost}" Grid.Column="0" Grid.Row="5" VerticalAlignment="Center" />
        <TextBox Text="{Binding Product.StandardCost, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, 
                 Converter={StaticResource PositiveDecimalConverter}}"
                 IsEnabled="{Binding IsBaseFareAmountEnabled}"
                 MaxLength="100" Grid.Column="1" Grid.Row="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" />
        <ContentControl Grid.Column="2" Grid.Row="5" Style="{DynamicResource ChangeMarker}" 
                        util:ChangeMarker.Entity="{Binding Product}" util:ChangeMarker.PropertyName="StandardCost" />

        <Label Content="{x:Static p:Resources.DiscontinuedDate}" Grid.Column="3" Grid.Row="5" VerticalAlignment="Center" />
        <!--<DatePicker Name="dp" Grid.Column="4" Grid.Row="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" 
                    SelectedDate="{Binding DiscontinuedDate}" />-->
        <TextBox Text="{Binding Product.DiscontinuedDate, StringFormat=d, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, 
                 ValidatesOnDataErrors=true, NotifyOnValidationError=true, TargetNullValue={x:Static sys:String.Empty}}"
                 MaxLength="100" Grid.Column="4" Grid.Row="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" />
        <ContentControl Grid.Column="5" Grid.Row="5" Style="{DynamicResource ChangeMarker}" 
                        util:ChangeMarker.Entity="{Binding Product}" util:ChangeMarker.PropertyName="DiscontinuedDate" />

        <!-- row 6 -->
        <Label Content="{x:Static p:Resources.Category}" Grid.Column="0" Grid.Row="6" VerticalAlignment="Center" />
        <ComboBox Grid.Column="1" Grid.Row="6" HorizontalAlignment="Stretch" VerticalAlignment="Center" 
                  ItemsSource="{Binding Categories}" SelectedItem="{Binding Product.ProductCategory}" DisplayMemberPath="Name" />
        <ContentControl Grid.Column="2" Grid.Row="6" Style="{DynamicResource ChangeMarker}" 
                        util:ChangeMarker.Entity="{Binding Product}" util:ChangeMarker.PropertyName="ProductCategory" />

        <!-- row 7 -->
        <Label Content="{x:Static p:Resources.Notes}" Grid.Column="0" Grid.Row="7" VerticalAlignment="Top" ToolTip="{x:Static p:Resources.NotesInfo}" />
        <TextBox Text="{Binding Product.Notes, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, 
                 ValidatesOnDataErrors=true, NotifyOnValidationError=true, TargetNullValue={x:Static sys:String.Empty}}"
                 Grid.Column="1" Grid.Row="7" Grid.ColumnSpan="4"
                 Height="60" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                 AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible"
                 ToolTip="{x:Static p:Resources.NotesInfo}" />
        <ContentControl Grid.Column="5" Grid.Row="7" Style="{DynamicResource ChangeMarker}" 
                        util:ChangeMarker.Entity="{Binding Product}" util:ChangeMarker.PropertyName="Notes" />

        <!-- row 8 -->
        <Label Content="{x:Static p:Resources.Status}" Grid.Column="0" Grid.Row="8" VerticalAlignment="Center" />
        <Label Content="{Binding Product.ChangeTracker.State}" Grid.Column="1" Grid.Row="8" 
               VerticalAlignment="Center" HorizontalAlignment="Left" IsEnabled="False" />
        <Label Content="{Binding Product.rowguid}" Grid.Column="1" Grid.Row="8" Grid.ColumnSpan="4" 
               VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,10" IsEnabled="False" />

        <!-- row 10 -->
        <Button Grid.Column="4" Grid.Row="10" Content="Reset" Command="{Binding RevertChangesCommand}" 
                VerticalAlignment="Bottom" HorizontalAlignment="Right" Padding="10 2" />
    </Grid>

</UserControl>
